package day16.tarena.GUI;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import java.awt.event.*;
public class TestEvent implements ActionListener{		//1
	private int count = 0;
	JLabel jl = new JLabel("  你点了0此");								//2
	public void actionPerformed(ActionEvent e) {
		String comm = e.getActionCommand();
		System.out.println(comm);
		if("+".equals(comm)){
			count++;
		}else{
		count--;
		}
		jl.setText("你点了"+count+"次");
		System.out.println(jl.getText());
	}			//改变JL上的文字,jl。setText("文字");jl.getText();

	public TestEvent (){
		JFrame jf = new JFrame("Test Event!");
		JButton jb1 = new JButton("+");
		JButton jb2 = new JButton("-");
		FlowLayout fl = new FlowLayout();
		jf.setLayout(fl);
		jf.add(jl);
		jf.add(jb1);
		jf.add(jb2);
		jb1.addActionListener(this);
		jb2.addActionListener(this);
		jf.setLocation(300,200);
		jf.setSize(300,200);
		jf.setVisible(true);
		jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
	
	public static void main(String[] args) {
		new TestEvent();
	}
}
